//
//  ChooseTableViewCell.m
//  19-CarHomeWork
//
//  Created by 曹曹 on 16/8/9.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ChooseTableViewCell.h"
#import "ChoseCollectionViewCell.h"
#import "CCList.h"

@interface ChooseTableViewCell () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;
@end

@implementation ChooseTableViewCell

- (void)layoutSubviews {
    [super layoutSubviews];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.contentSize = CGSizeMake(CGRectGetWidth(self.bounds), 0);
    _collectionView.backgroundColor = [UIColor whiteColor];
    _layout.itemSize = CGSizeMake((self.contentView.frame.size.width - 50) / 4, (CGRectGetHeight(self.bounds) - 30) / 2);
    _layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    _layout.minimumLineSpacing = 5;
    _layout.minimumInteritemSpacing = 0;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        if (_list) {
            [self.collectionView reloadData];
        }
        
    });
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _list.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ChoseCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"chose" forIndexPath:indexPath];
    ;
    [cell.button setTitle:_list[indexPath.row].name forState:UIControlStateNormal];
    return cell;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
